<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title>订单查询 - WMS仓库管理系统</title>
</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">

<div class="layui-body" style="padding:15px;top: 0px;">
    <style type="text/css">
        .T-box {
            width: 400px;
            padding: 0 20px;
            text-align: left;
        }

        .T-box p {
            position: relative;
            height: 36px;
            line-height: 36px;
            font-size: 14px;
            margin-bottom: 15px;
        }

        .T-box p span {
            display: inline-block;
            padding-right: 15px;
            text-align: right;
            width: 110px;
            line-height: 36px;
            font-size: 14px;
        }

        .T-box p input, .T-box p select {
            width: 160px;
            padding: 0 5px;
            height: 34px;
            line-height: 34px;
            font-size: 14px;
            border: 1px solid #d3d3d3;
            outline: none;
        }

        .T-box p i {
            padding: 0 10px;
            line-height: 36px;
            font-style: normal;
        }

        .T-box p b {
            display: inline-block;
            margin-left: 10px;
            cursor: pointer;
            width: 60px;
            height: 36px;
            line-height: 36px;
            background: #c33;
            color: #fff;
            text-align: center;
            font-size: 13px;
            font-weight: normal;
        }

        .T-result {
            margin-bottom: 0;
        }

        .T-result em {
            color: #c33;
            font-style: normal;
        }
    </style>
    <!-- start sp-wrapper -->
    <fieldset class="layui-elem-field">
        <legend>按条件搜索</legend>
        <div class="layui-field-box">
            <div class="layui-form-item">

                <div class="layui-inline">
                    <form method="post" enctype="multipart/form-data" id="execl_form">
                        <input type="file" name="excel" id="excel" placeholder="excel" class="layui-input">
                    </form>
                </div>
                <div class="layui-inline">
                    <button type="button" id="excel_upload_btn" class="layui-btn">导入抖音结算订单</button>
                </div>
            </div>
            <form class="layui-form layui-form-pane1" method="get" th:action="${searchUrl}">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="text" name="orderNum" th:value="${orderNum}" placeholder="订单编号" class="layui-input">
                    </div>
<!--                    <div class="layui-inline">-->
<!--                        <input type="text" name="mobile" th:value="${mobile}" placeholder="收货人手机号" class="layui-input">-->
<!--                    </div>-->
                    <div class="layui-inline">
                        <input type="text" name="logisticsCode" th:value="${logisticsCode}" placeholder="快递单号" class="layui-input">
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">下单时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="startTime" id="startTime" placeholder="yyyy-MM-dd" th:value="${startTime}" autocomplete="off">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="endTime" id="endTime" placeholder="yyyy-MM-dd" th:text="${endTime}" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <select id="saleType" name="saleType" >
                            <option value="">销售类型</option>
                            <option value="1">实售</option>
                            <option value="0">样品</option>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn">搜索</button>
                        <i>总共：&nbsp;[[${totalSize}]]&nbsp;条记录</i>
                    </div>
                    <div class="layui-inline" >
                        <a class="layui-btn layui-btn-primary" href="javascript:;" id="export_order">导出结算订单</a>
                    </div>

                    <div class="layui-inline"></div>

                </div>
            </form>



        </div>
    </fieldset>

    <link rel="stylesheet" href="/sb/stock.css"/>
    <div class="sp-wrapper">
        <div class="sp-table">
            <table>
                <thead>
                <tr>
                    <th>ID</th>
                    <th>订单信息</th>

                    <th>商品信息</th>
                    <th>收货信息</th>
                    <th>物流信息</th>
                    <th>所属店铺</th>
                    <th>销售类型</th>
                    <th>订单备注</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="sp-data">
                <tr th:each="item:${list}">
                    <td th:text="${item.id}">1</td>
                    <td>
                        <p>订单号：<b th:text="${item.order_num}"></b></p>
                        <p>下单时间：<b th:text="${#dates.format(item.orderTime * 1000,'yyyy-MM-dd HH:mm:ss')}"></b></p>
<!--                        <p>拣货完成时间：<b th:text="${#dates.format(item.pickedTime * 1000,'yyyy-MM-dd HH:mm:ss')}"></b></p>-->
                        <p th:if="${item.stockOutTime != null && item.stockOutTime > 0}">出库时间：<b th:text="${#dates.format(item.stockOutTime * 1000,'yyyy-MM-dd HH:mm:ss')}"></b></p>
                        <p th:if="${item.deliveryTime != null && item.deliveryTime > 0}">发货时间：<b th:text="${#dates.format(item.deliveryTime * 1000,'yyyy-MM-dd HH:mm:ss')}"></b></p>
                    </td>
                    <td>
                        <div>
                            总共<span style="color: red;font-size: large">[[${item.totalQuantity}]]</span> 件商品<p><i class="goods_list" th:attr="data-id=${item.getId()}">查看详情</i></p>

                        </div>
                    </td>
                    <td>
                        <p><b th:text="${item.contactPerson}"></b>&nbsp;<b th:text="${item.mobile}"></b></p>

                        <p>
                            <b th:text="${item.province}"></b>&nbsp;
                            <b th:text="${item.city}"></b>&nbsp;
                            <b th:text="${item.area}"></b></p>
                        <p>
                            <b th:text="${item.address}"></b>
                        </p>
                    </td>
                    <td>
                        <div>
                            <p th:if="${#strings.isEmpty(item.logisticsCompany)==false}"><b
                                    th:text="${item.logisticsCompany}"></b></p>
                            <p th:if="${#strings.isEmpty(item.logisticsCode)==false}"><i
                                    th:text="${item.logisticsCode}"></i></p>
                        </div>
                    </td>
                    <td th:text="${item.shopName}"></td>
                    <td >
                        <b th:if="${item.saleType == 0}">样品</b>
                        <b th:if="${item.saleType == 1}">实售</b>
                    </td>
                    <td >
                        <b th:text="${item.sellerMemo}"></b>
                        <b th:text="${item.remark}"></b>
                    </td>

                    <td >
                        <b th:text="${T(com.b2c.erp.enums.EnumErpOrderSendStatus).getName(item.status)}"></b><br />
                       <!-- <b th:text="${T(com.b2c.erp.enums.EnumErpOrderlogisticsPrintStatus).getName(item.logisticsPrintStatus)}"></b>-->
                        <u th:if="${item.logisticsPrintType==1}">(手填)</u>
                        <u th:if="${item.logisticsPrintType==2}">(打印)</u>
                        <br />

                    </td>
                    <!--<td ></td>-->
                    <td>
                        <p th:if="${item.getStatus()==T(com.b2c.erp.enums.EnumErpOrderSendStatus).HasOut.getIndex() && item.logisticsPrintType != 2}">
                            <i  class="hand_express" th:attr="data-id=${item.getId()}">手动填写快递单</i><br />
                        </p>
                        <p th:if="${item.getStatus() >= T(com.b2c.erp.enums.EnumErpOrderSendStatus).HasOut.getIndex() && item.logisticsPrintType != 1 }">
                            <i  class="print_express" th:attr="data-id=${item.getId()}">打印快递单</i><br />
                        </p>
                        <p><i class="print" th:attr="data-id=${item.getId()}">打印发货单</i><br /></p>
                        <p th:if="${item.getStatus()==T(com.b2c.erp.enums.EnumErpOrderSendStatus).HasOut.getIndex()}">
                            <i class="send" th:attr="data-id=${item.getId()}">订单发货</i>
                        </p>
                    </td>
                </tr>
                </tbody>
            </table>
            <div class="pages">
                <paging:pager th:value="${pageIndex}" th:rows="${totalSize}" th:size="${pageSize}"/>
            </div>
        </div>
    </div>
<!--    <script type="text/template" id="send-goods">
        <div class="T-box">
            <p><span>快递公司</span>
                <select id="send-company">
                    <option value="">请选择快递公司</option>
                    <option th:each="item:${company}" th:value="${item.getCode()}" th:text="${item.getName()}"></option>
                </select>
            </p>
            <p><span>快递单号</span><input type="text" name="express_code"/></p>
            <p class="T-result"><span>&nbsp;</span><em id="erro"></em></p>
        </div>
    </script>-->


    <script type="text/javascript" src="/sb/jquery.min.js"></script>
    <script type="text/javascript" src="/sb/Tips.min.js"></script>
    <script type="text/javascript">

        $(function () {
            function getDateTime(timestamp) {
                var date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
                var Y = date.getFullYear();
                var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
                var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
                var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours());
                var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes());
                var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
                return Y + '-' + M + '-' + D + ' ' + h + ':' + m + ':' + s;
            }
            //计算天数差的函数，通用
            function DateDiff(sDate1, sDate2) { //sDate1和sDate2是2019-3-12格式
                var aDate, oDate1, oDate2, iDays
                aDate = sDate1.split("-")
                oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) //转换为9-25-2017格式
                aDate = sDate2.split("-")
                oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])
                iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24) //把相差的毫秒数转换为天数
                return iDays
            }
            //导出订单
/*            $("#export_order").click(function () {
                var startDate = $("#startTime").val();
                var endDate = $("#endTime").val();
                if (startDate == '' || endDate == "") {
                    alert("导出订单一定要选择开始日期和结束日期");
                    return;
                } else {
                    var days = DateDiff(startDate, endDate);
                    if(days > 60){
                        alert("最多只能导出最近60天的数据");
                        return;
                    }
                    window.location.href = "/order/order_has_send_export?startDate=" + startDate + "&endDate=" + endDate;
                }
            })*/
            // 填写物流
            $('.hand_express').click(function (e) {
                e.stopPropagation();
                e.preventDefault();
                var id = $(this).attr('data-id');
                Tips.confirm({
                    title: '手动填写物流信息',
                    content: $('#send-goods').html(),
                    define: function () {
                        var data = {
                            id: id,
                            company: $("#send-company  option:selected").text(),
                            companyCode: $("#send-company  option:selected").val(),
                            code: $("input[name='express_code']").val()
                        };
                        $.ajax({
                            url: "/ajax_order/order_hand_express",
                            type: "POST",
                            dataType: 'json',
                            contentType: 'application/json',
                            data: JSON.stringify(data),
                            success: function (res) {
                                if (res.code == 0) {
                                    Tips.alert('成功', function () {
                                        location.reload(true);
                                    });
                                } else {
                                    Tips.alert(res.msg);
                                }
                            }
                        });
                    }
                });
            });

            $("#export_order").click(function () {
                //组合条件
                var url = "/order/douyin_order_settle_export";
                var startTime = $("input[name=startTime]").val();
                var endTime = $("input[name=endTime]").val();

                if (startTime != '') {
                    url += "?startTime=" + startTime;
                }
                if (startTime != '') {
                    url += "&endTime=" + endTime;
                }
                window.open(url, "_blank");
            })
            $("#excel_upload_btn").click(function () {
                var excel = $("#excel").val();
                if (excel == '') {
                    alert("请选择文件");
                    return false;
                } else if (excel.lastIndexOf(".xls") < 0) {//可判断以.xls和.xlsx结尾的excel
                    alert("只能上传Excel文件");
                } else if (excel.lastIndexOf(".xlsx") < 0) {
                    alert("只能上传Excel文件");
                } else {
                    var url = "/ajax_order/douyin_order_settle_import";
                    // var formData = new FormData($('#execl_form')[0]);

                    var formData = new FormData();
                    formData.append("excel", document.getElementById("excel").files[0]);
                    $(this).hide();
                    $("#excel_upload_btn_").show();
                    $.ajax({
                        url: url,
                        type: "post",
                        data: formData,
                        success: function (result) {
                            $("#excel_upload_btn_").hide();
                            $("#excel_upload_btn").show();
                            // console.log(result);
                            if (result.code == 0) {
                                alert("导入成功");
                            } else {
                                alert("更新失败:" + result.msg);
                            }
                            // alert(JSON.stringify(result));
                            return false;
                        },
                        error: function () {
                            alert("excel上传失败");
                        },
                        cache: false,
                        contentType: false,
                        processData: false
                    });
                }

                return false;
            })
        });
    </script>
    <!-- end sp-wrapper -->
    <script>
        layui.use(['laydate', 'layer','form'], function () {
            var laydate = layui.laydate;
            var layer = layui.layer;
            var form = layui.form;

            laydate.render({
                elem: '#startTime'
            });
            laydate.render({
                elem: '#endTime'
            });
            $(function () {
                $("#saleType").val([[${saleType}]]);
                form.render('select'); //刷新select选择框渲染
            });
            //弹出商品list
            $(".goods_list").click(function () {
                var id = $(this).attr("data-id");
                layer.open({
                    type: 2,
                    title: '订单商品列表',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['940px', '90%'],
                    content: '/order/order_goods_list?id=' + id //iframe的url
                });
            })

            //打印快递单弹窗

            $(".print_express").click(function () {
                var id = $(this).attr("data-id");
                // console.log(id);
                //iframe层
                layer.open({
                    type: 2,
                    title: '打印订单快递单',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['940px', '90%'],
                    content: '/order/order_send_express?id=' + id //iframe的url
                });
            })

            //打印发货单弹窗
            $(".print").click(function () {
                var id = $(this).attr("data-id");
                console.log(id);
                //iframe层

                layer.open({
                    type: 2,
                    title: '打印订单发货单',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['940px', '90%'],
                    content: '/order/order_send_invoice?id=' + id //iframe的url
                });
            })

            //订单出库（发货）弹窗
            $(".send").click(function () {
                var id = $(this).attr("data-id");
                console.log(id);
                //iframe层

                layer.open({
                    type: 2,
                    title: '订单出库（发货）',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['940px', '90%'],
                    content: '/order/order_send?id=' + id //iframe的url
                });
            })

            //更新需要打印的订单数据
            $("#updatePickedOrder").click(function () {
                // $.ajax
                $.ajax({
                    url: "/ajax_order/update_picked_order",
                    type: "POST",
                    dataType: 'json',
                    contentType: 'application/json',
                    success: function (res) {
                        alert("更新了" + res.data + "条数据");
                        window.location.reload();
                    }
                });
            });//结束更新


        });
    </script>
</div>
</body>
<html>
